<template>
    <div >
        <!--    搜索表单-->
        <div style="margin-bottom: 20px">
            <el-divider ></el-divider>
            <div style="float: left;margin-top: 3px">
                <i  style="font-size: x-large" class="el-icon-document-checked"></i><span style="margin-left:10px;font-weight:bold;font-size:x-large">发药</span>
            </div>
            <el-input v-model="caseNumber" style="width: 270px;margin-left: 25px;float: left;" placeholder="请输入患者病历号" ></el-input>
            <el-input v-model="realName" style="width: 270px;margin-left: 25px; float: left;" placeholder="请输入患者姓名" ></el-input>
            <el-button style="margin-left: 25px" type="primary" @click="selectRegister"> 搜索</el-button>
        </div>
        <el-divider ></el-divider>
        <el-table :data="registerList" height="200" style="width: 100%">
            <el-table-column label="编号" prop="id">
            </el-table-column>
            <el-table-column label="患者姓名" prop="realName">
            </el-table-column>
            <el-table-column label="患者病历号" prop="caseNumber">
            </el-table-column>
            <el-table-column label="患者年龄" prop="age">
            </el-table-column>
            <el-table-column label="患者性别" prop="gender">
            </el-table-column>
            <el-table-column>
                <template slot-scope="register">
                    <el-button type="primary" style="float:right;margin-right: 30px;" @click="selectPrescriptionDrugInfo(register.row.id)">显示药品</el-button>

                </template>
            </el-table-column>
        </el-table>
        <el-divider ></el-divider>
        <el-table :data="drugPrescriptionList" height="300" style="width: 100%">
            <el-table-column type="index" width="50">
            </el-table-column>
            <el-table-column label="药品编码" prop="drugCode">
            </el-table-column>
            <el-table-column label="药品名称" prop="drugName">
            </el-table-column>
            <el-table-column label="药品规格" prop="drugFormat">
            </el-table-column>
            <el-table-column label="包装单位" prop="drugUnit">
            </el-table-column>
            <el-table-column label="生产厂家" prop="manufacturer">
            </el-table-column>
            <el-table-column label="单价" prop="drugPrice">
            </el-table-column>
            <el-table-column label="药品数量" prop="drugNumber">
            </el-table-column>
            <el-table-column >
                <template slot-scope="prescriptionDrug">
                    <el-button type="primary" @click="distribute(prescriptionDrug.row),dialogFormVisible = true">发药</el-button>
                </template>
            </el-table-column>
        </el-table>

    </div>
</template>
<script>
    import axios from "axios";

    axios.defaults.baseURL='http://127.0.0.1:8088/drugInfo';
    export default {
        created() { //页面加载时执行查询方法
        },
        data() {

            return {
                Id:"",
                id:"",
                realName:"",
                caseNumber:"",
                age:"",
                gender:"",
                registerList:[],
                drugPrescriptionList:[],
                formLabelWidth: '120px',
                dialogForm:"",
                dialogFormVisible:false,

            }

        },
        methods: {
            selectRegister(){
                axios.post('/selectRegister',{
                    caseNumber:this.caseNumber,
                    realName:this.realName,
                }).then(response=>{
                    console.log(response.data);
                    this.registerList=response.data.data
                    this.$message({
                        message: '查找患者成功',
                        type: 'success'
                    });
                }).catch(error=>{
                    console.log(error)
                });
            },
            selectPrescriptionDrugInfo(id){
                axios.post('/selectPrescriptionDrugInfo',{
                    id:id,
                }).then(response=>{
                    console.log(response.data);
                    this.drugPrescriptionList=response.data.data
                    console.log(this.drugPrescriptionList)
                    this.$message({
                        message: '查询处方成功',
                        type: 'success'
                    });
                }).catch(error=>{
                    console.log(error)
                });
            },
            distribute(row){
                axios.post('/updateDrugState',{
                    Id:row.id,
                }).then(response=>{
                    console.log(response.data);
                    this.drugPrescriptionList=response.data.data
                    this.$message({
                        message: '修改成功',
                        type: 'success'
                    });
                }).catch(error=>{
                    console.log(error)
                });

            }
        }
    }
</script>
<style scoped>
</style>